<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/xheditor/xheditor.js"></script>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<script type="text/javascript">
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme: 'facebook'});
	$("#submit").click(function(){
		if ( ! $("#number").val())
		{
			alert("查找编号还没填写");
			return false;
		}
	});
	$(".toggle").click(function(){
		$(this).parent().next().toggle();
	});
	$("#new_save").click(function(){
		var lang = $("#new_lang").val();
		var title = $("#new_title").val();
		var desc = $("#new_desc").val();
		if (lang.length == 0)
		{
			alert("请选择描述的语种！");
			return false;
		}
		if ( ! $.trim(title))
		{
			alert("标题不能为空！");
			return false;
		}
		if ( ! $.trim(desc))
		{
			alert("描述不能为空！");
			return false;
		}
	});
});
</script>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>输查找编号</th>
	<td><input type="text" name="number" id="number" value="<?=isset($_GET['number']) ? $_GET['number'] : ''?>" /></td>
	<td>
		<input type="submit" id="submit" class="button" value="查询" />
	</td>
</tr>
</table>
</form>
<?if (isset($_GET['number'])):?>
<table width="100%" class="list_table" cellpadding="0" cellspacing="0">
	<tr>
		<td width="50%" valign="top">
			<div style=" width: 100%;">
				<?if (isset($message)):?>
					<span id="message" class="red"><?=$message?></span>
				<?endif;?>
				<?if (isset($product_info)):?>
				<table class="list_table" width="100%">
					<tr>
						<td width="65">产品编号</td>
						<td align="left">
							<b><?=isset($product['number']) ? $product['number'] : ''?></b>
							<a href="<?=url('Online::ProductInfo/Detail', array('number' => $product['number']));?>" style="float: right;">新建</a>
						</td>
					</tr>
					<tr>
						<td>产品名称</td>
						<td align="left">
							<?=isset($product['name']) ? $product['name'] : ''?>
						</td>
					</tr>
					<tr>
						<td>产品图片</td>
						<td align="left" valign="middle">
							<?if (isset($product['pic_url']) && $product['pic_url']):?>
								<?$pretty_photo_number = 0;?>
								<?foreach ($product['pic_url'] as $p):?>
								<a rel="pretty_photo[1]" href="<?=$p?>"><?if(!$pretty_photo_number):?><img width="100" src="<?=$p?>" /><?endif;?></a>
								<?$pretty_photo_number = 1;?>
								<?endforeach;?>
							<?endif;?>			
						</td>
					</tr>
					<?foreach ($product_info as $pi):?>
					<tr>
						<td class="toggle" align="left" colspan="2">
							<a style="font-size: 15px; font-weight: bolder;">+</a>
							<?foreach (Q::ini('custom_flag/online_ebay_product_language') as $l):?>
							<?if ($pi['lang'] && $pi['lang'] == $l['value']):?>(<?=$l['name']?>)<?endif;?>
							<?endforeach;?>
							<?=isset($pi['title']) ? htmlspecialchars($pi['title']) : ''?>
							<a class="btn_edit" href="<?=url('Online::ProductInfo/Detail', array('number' => $product['number'], 'product_info_id' => $pi['id']));?>" style="float: right;">编辑</a>
						</td>
					</tr>
					<tr class="desc">
						<td colspan="2" align="left">
							<textarea rows="8" cols="90%"><?=htmlspecialchars($pi['description'])?></textarea>
						</td>
					</tr>
					<?endforeach;?>
				</table>
				<span class="red">*已创建描述 , 点击"+"可隐藏和查看产品详细资料*</span>
			</div>
		</td>
		<td width="50%" valign="top" align="left">
			<?if ( ! isset($product_edit['form'])): ?>
			<div id="new" style="width:100%; display:block; ">
				<?if ( ! empty($language)):?>
				<form action="<?=url('Online::ProductInfo/CreateSave')?>" method="post" >
					<table class="list_table" width="100%">
						<tr><td colspan="2" align="center"><h3>新建产品资料</h3></td></tr>
						<tr>
							<th width="65">描述语种</th>
							<td align="left">
								<select name="lang" id="new_lang">
									<option value="">请选择</option>
									<?foreach ($language as $l):?>
									<option value="<?=$l['value']?>"><?=$l['name']?></option>
									<?endforeach;?>
								</select>		
							</td>
						</tr>
						<tr>
							<th>产品标题</th>
							<td align="left">
								<input type="text" name="title" id="new_title" size="81" value=""/>
							</td>
						</tr>
						<tr>
							<th>产品描述</th>
							<td align="left">
								<textarea rows="20" cols="80" class="xheditor {tools: 'Blocktag, Fontface, FontSize, Bold, Italic, Underline, Strikethrough, FontColor, BackColor, Removeformat, Align, List, Outdent, Indent, Link, Unlink, Img, Flash, Table, Source, Fullscreen')" name="description" id="new_desc">
								</textarea>
							</td>
						</tr>
						<tr>
							<td colspan="2"><input type="hidden" name="product_basic_id" value="<?=isset($product['id']) ? $product['id'] : ''?>" /><input type="submit" class="button" id="new_save" value="保存" /></td>
						</tr>
					</table>
				</form>
				<?else:?>
				<span style="margin-left: 100px;" class="red">该产品所有语种描述都已创建,可点击编辑修改!</span>
				<?endif;?>
			</div>
			<?endif;?>
			<?endif;?>
			<?if (isset($product_edit['id']) && isset($product_edit['form']) && $product_edit['form'] == 'edit'): ?>
			<div id="edit" style=" width:100%; display:block;">
				<form action="<?=url('Online::ProductInfo/EditSave')?>" method="post">
					<table class="list_table" width="100%" cellpadding="0" cellspacing="0" border="0">
						<tr>
							<td colspan="2" align="center"><h3>编辑产品资料</h3></td>
						</tr>
						<tr>
							<th width="65">描述语种</th>
							<td align="left">
								<select name="lang" id="edit_lang"  disabled="disabled">
									<option value="">请选择</option>
									<?foreach (Q::ini('custom_flag/online_ebay_product_language') as $l):?>
										<option value="<?=$l['value']?>" <?if ($product_edit['lang'] && $product_edit['lang'] == $l['value']):?>selected="selected"<?endif;?>><?=$l['name']?></option>
									<?endforeach;?>
								</select>		
							</td>
						</tr>
						<tr>
							<th>产品标题</th>
							<td align="left"><input type="text" name="title" id="edit_title" size="81" value="<?=$product_edit['title']?>"/></td>
						</tr>
						<tr>
							<th>产品描述</th>
							<td align="left">
								<textarea rows="20" cols="80" class="xheditor {tools: 'Blocktag, Fontface, FontSize, Bold, Italic, Underline, Strikethrough, FontColor, BackColor, Removeformat, Align, List, Outdent, Indent, Link, Unlink, Img, Flash, Table, Source, Fullscreen')" name="description" id="edit_desc">
								<?=$product_edit['description']?>
								</textarea>
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<input type="hidden" name="id" value="<?=$product_edit['id']?>" />
								<input type="submit" class="button" id="edit_save" value="保存" />
							</td>
						</tr>
					</table>
				</form>
			</div>
			<?endif;?>
		</td>
	</tr>
</table>
<?endif;?>
<?php $this->_endblock();?>